package com.qf.electronic.common;

import lombok.Getter;
//这个类就是统一返回结果的封装类
@Getter
public class R<T> {

    private final int status;

    private final String msg;

    private final T data;

    private R(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <E> R<E> ok(E data){
        return new R<>(ResponseStatus.OK.getStatus(), ResponseStatus.OK.getMsg(), data);
    }

    public static <E> R<E> error(ResponseStatus status){
        return error(status.getStatus(), status.getMsg());
    }

    public static <E> R<E> error(int status, String msg){
        return new R<>(status, msg, null);
    }

    public static <E> R<E> error(int status){
        return error(status, "");
    }
}
